import numpy as np
import pandas as pd
import cv2


def DrawGreyImg(las):
    # 格式转换
    all_df = pd.DataFrame(las.data, columns=las.keys())
    df = pd.concat([all_df.iloc[:, 2:10], all_df.iloc[:, 2]], axis=1)

    # 将DataFrame转换为numpy数组
    data = df.values

    # 确保数据是二维的
    if data.ndim != 2:
        raise ValueError("数据必须是二维的")

    # 将数据归一化到0-255之间
    data_normalized = (data - data.min()) / (data.max() - data.min()) * 255

    # 转换为8位整数
    data_uint8 = data_normalized.astype(np.uint8)

    # 创建灰度图像
    gray_image = data_uint8
    resized_image = cv2.resize(gray_image, (500, 3000), interpolation=cv2.INTER_LINEAR)  ###此处设置图像尺寸，2比50

    # 保存图像
    cv2.imwrite('asset/gammaImg.png', resized_image)

    # 显示图像
    # cv2.imshow('resized Image', resized_image)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


